package com.my.java.mq.kafka;

import java.util.Arrays;
import java.util.Properties;

import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;

public class MyCustomer {

        public static void main(String[] args) {
                Properties props = new Properties();
                props.put("bootstrap.servers", KafkaConstant.DOMAIN+":9092");
                props.put("group.id", "test");
                props.put("enable.auto.commit", "true");
                props.put("auto.commit.interval.ms", "1000");
                props.put("session.timeout.ms", "30000");
                props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
                props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");

                Consumer<String, String> consumer = new KafkaConsumer<String, String>(props);
                consumer.subscribe(Arrays.asList("message"));
                while (true) {
                        ConsumerRecords<String, String> records = consumer.poll(10);
                        for (ConsumerRecord<String, String> record : records) {
                                System.out.println("offset=" + record.offset() + ",--key=" + record.key() + ",--value=" + record.value());
                        }
                }
        }
}
